//                       .::::.
//                     .::::::::.
//                    :::::::::::
//                 ..:::::::::::'
//              '::::::::::::'
//                .::::::::::
//           '::::::::::::::..
//                ..::::::::::::.
//              ``::::::::::::::::
//               ::::``:::::::::'        .:::.
//              ::::'   ':::::'       .::::::::.
//            .::::'      ::::     .:::::::'::::.
//           .:::'       :::::  .:::::::::' ':::::.
//          .::'        :::::.:::::::::'      ':::::.
//         .::'         ::::::::::::::'         ``::::.
//     ...:::           ::::::::::::'              ``::.
//    ```` ':.          ':::::::::'                  ::::..
//                       '.:::::'                    ':'````..
package com.xw.controller.manage;

import com.github.pagehelper.PageHelper;
import com.xw.model.Banner;
import com.xw.model.DicGroupLimit;
import com.xw.service.BannerService;
import com.xw.service.sysconfig.DicGroupLimitService;
import com.xw.util.JsonData;
import com.xw.util.PropertiesUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * banner
 */
@Controller
@RequestMapping("/manage/banner/")
@Scope("prototype")
public class BannerController {
    @Resource
    private BannerService bannerService;
    @Resource
    private DicGroupLimitService groupLimitService;

    /**
     * 删除
     * @return
     */
    @RequestMapping(value = "del",method = RequestMethod.POST)
    @ResponseBody
    public Map del(String id){
        Map map =bannerService.del(id);
        return map;
    }

    /**
     * 修改banner
     * @return
     */
    @RequestMapping("edit")
    @ResponseBody
    public Map edit(Banner banner){
        return bannerService.edit(banner);
    }

    /**
     * 跳转到编辑页面
     * @return
     */
    @RequestMapping(value = "goEdit",method = RequestMethod.GET)
    public String goEdit(HttpServletRequest request,String bannerId){
        Banner banner = bannerService.findByKeyId(bannerId);
        request.setAttribute("model",banner);
        request.setAttribute("url",PropertiesUtil.getProperty("URL"));
        return "banner/edit";
    }

    /**
     * 添加banner
     * @return
     */
    @RequestMapping("add")
    @ResponseBody
    public Map add(Banner banner){
        return bannerService.add(banner);
    }

    /**
     * 跳转到新增页面
     * @return
     */
    @RequestMapping(value = "goAdd",method = RequestMethod.GET)
    public String goAdd(HttpServletRequest request){
        request.setAttribute("url",PropertiesUtil.getProperty("URL"));
        return "banner/add";
    }

    /**
     * 跳转到商品分类列表页面
     * @return
     */
    @RequestMapping(value = "findAll",method = RequestMethod.GET)
    public String findAll(HttpServletRequest request, String glId){
        //查询该子导航的增删改查的权限
        DicGroupLimit model = groupLimitService.queryByUUID(glId);
        request.setAttribute("model",model);
        request.setAttribute("url",PropertiesUtil.getProperty("URL"));
        return "banner/list";
    }

    /**
     * 获取列表数据
     * @return
     */
    @RequestMapping(value = "findAllJson",method = RequestMethod.GET)
    @ResponseBody
    public Object findAllJson(Integer page,Integer limit){
        Integer count=bannerService.findByWhere().size();
        if (page >0 & limit >0){
            PageHelper.startPage(page,limit,false);
        }
        List<Banner> list=bannerService.findByWhere();
        return JsonData.returnLayuiMap(list, count);
    }
}
